package com.sitia.jd.controller;

import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.core.page.TableDataInfo;
import com.sitia.common.enums.BusinessType;
import com.sitia.common.utils.poi.ExcelUtil;
import com.sitia.jd.domain.MxProductsThird;
import com.sitia.jd.domain.vo.MxProductsThirdVo;
import com.sitia.jd.service.IMxProductsThirdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 第三方商品Controller
 * 
 * @author sitia
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/third/products")
public class MxProductsThirdController extends BaseController
{
    @Autowired
    private IMxProductsThirdService mxProductsThirdService;

    /**
     * 查询第三方商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MxProductsThird mxProductsThird)
    {
        startPage();
        List<MxProductsThird> list = mxProductsThirdService.selectMxProductsThirdList(mxProductsThird);
        return getDataTable(list);
    }

    /**
     * 导出第三方商品列表
     */
    @Log(title = "第三方商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxProductsThird mxProductsThird)
    {
        List<MxProductsThird> list = mxProductsThirdService.selectMxProductsThirdList(mxProductsThird);
        ExcelUtil<MxProductsThird> util = new ExcelUtil<MxProductsThird>(MxProductsThird.class);
        util.exportExcel(response, list, "第三方商品数据");
    }

    /**
     * 获取第三方商品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mxProductsThirdService.selectMxProductsThirdById(id));
    }

    /**
     * 新增第三方商品
     */
    @Log(title = "第三方商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxProductsThird mxProductsThird)
    {
        return toAjax(mxProductsThirdService.insertMxProductsThird(mxProductsThird));
    }

    /**
     * 推送数据
     * @param mxProductsThird
     * @return
     */
    @PostMapping("/pushData")
    public AjaxResult add(@RequestBody  List<MxProductsThirdVo> vo)
    {
        return toAjax( mxProductsThirdService.pushDataByKFJ(vo));
    }

    /**
     * 修改第三方商品
     */
    @Log(title = "第三方商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxProductsThird mxProductsThird)
    {
        return toAjax(mxProductsThirdService.updateMxProductsThird(mxProductsThird));
    }

    /**
     * 删除第三方商品
     */
    @Log(title = "第三方商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mxProductsThirdService.deleteMxProductsThirdByIds(ids));
    }


}
